import 'package:flutter/material.dart';

class PageViewFullPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _PageViewFullPageState();
  }
}

class _PageViewFullPageState extends State<PageViewFullPage> {
  List<Widget> list = [];

  @override
  void initState() {
    super.initState();
    for (int i = 0; i < 10; i++) {
      list.add(Container(
        child: Center(
          child: Text("第${i + 1}页", style: const TextStyle(fontSize: 30, color: Colors.blue)),
        ),
      ));
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("抖音无线滑动"),
      ),
      body: PageView(
        scrollDirection: Axis.vertical,
        onPageChanged: (index) {
          print(index);
          //无限加载
          if (index + 2 == list.length) {
            setState(() {});
            for (int i = 0; i < 10; i++) {
              list.add(Container(
                child: Center(
                  child: Text("第${i + 1}页", style: const TextStyle(fontSize: 30, color: Colors.blue)),
                ),
              ));
            }
          }
        },
        children: list,
      ),
    );
  }
}
